package isPathCrossing;

import java.util.HashSet;
import java.util.Set;

public class Solution {
    public boolean isPathCrossing(String path) {
        // 记录点(x,y)
        // x.y
        Set<Integer> set = new HashSet<>();
        int x = 0,y = 0;
        for (int i = 0; i < path.length(); i++) {
            switch (path.charAt(i)) {
                case 'N' ->{
                    y++;
                }
                case 'S' ->{
                    y--;
                }
                case 'E' ->{
                    x++;
                }
                case 'W' ->{
                    x--;
                }
            }
            int t = x*10000+y*10000;
            if(set.contains(t))return true;
            set.add(t);
        }
        return false;
    }
}
